package org.lanzier.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


/**
 * @author lansb
 * 过滤器
 */
public class CheckLoginInterceptor implements HandlerInterceptor {
	private static Logger logger = Logger.getLogger("interceptor");
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object arg2, Exception arg3)
			throws Exception {
		//实现如下:
		System.out.println("ControllerInterceptor.afterCompletion()");
	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response,
			Object arg2, ModelAndView arg3) throws Exception {
		//实现如下:
		System.out.println("ControllerInterceptor.postHandle()");
	}

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object arg2) throws Exception {
		//实现如下:
		System.out.println("ControllerInterceptor.preHandle()");
		//String reqUrl = rq.getServletPath();  
		HttpSession session = request.getSession();
		Object logininfo = session.getAttribute("logininfo");
		System.out.println("***************************");
		System.out.println("enter interceptor");
		System.out.println("***************************");
		//判断session
		if(logininfo == null) {
			String servletPath = request.getServletPath();
			logger.info("********************");
			logger.info(servletPath);
			logger.info("********************");
			//response.sendRedirect("");
			System.out.println("servletPath=>" + servletPath);
			return true;
		}
		//String staffId = ((Map)logininfo).get("STAFF_ID").toString();
		//判断权限
		//mapperDao.selectString("common.", staffId);
		return true;
	}
	
}
